package com.ruoyi.generator.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.generator.domain.ReverseGenTableColumnMap;
import com.ruoyi.generator.service.IReverseGenTableColumnMapService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.utils.excel.*;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 反向生成字段映射Controller
 * 
 * @author Jason
 * @date 2022-02-09
 */
@RestController
@RequestMapping("/generator/ReverseGenTableColumnMap")
public class ReverseGenTableColumnMapController extends BaseController
{
    @Autowired
    private IReverseGenTableColumnMapService reverseGenTableColumnMapService;

    /**
     * 查询反向生成字段映射列表
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:list')")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        startPage(reverseGenTableColumnMap);
        List<ReverseGenTableColumnMap> list = reverseGenTableColumnMapService.selectReverseGenTableColumnMapList(reverseGenTableColumnMap);
        return getDataTable(list);
    }

    /**
     * 查询反向生成字段映射列表
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:list')")
    @GetMapping("/listByIds/{mapIds}")
    public TableDataInfo listByIds(@PathVariable Long[] mapIds)
    {
        startPage();
        List<ReverseGenTableColumnMap> list = reverseGenTableColumnMapService.selectReverseGenTableColumnMapListByIds(mapIds);
        return getDataTable(list);
    }

    /**
     * 导出反向生成字段映射列表
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:export')")
    @Log(title = "导出反向生成字段映射", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        List<ReverseGenTableColumnMap> list = reverseGenTableColumnMapService.selectReverseGenTableColumnMapList(reverseGenTableColumnMap);
        ExcelUtil<ReverseGenTableColumnMap> util = new ExcelUtil<ReverseGenTableColumnMap>(ReverseGenTableColumnMap.class);
        return util.exportExcel(list, "ReverseGenTableColumnMap");
    }

    /**
     * 导出反向生成字段映射列表（包含样式）
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:export')")
    @Log(title = "导出反向生成字段映射", businessType = BusinessType.EXPORT)
    @PostMapping("/exportWithStyle")
    public AjaxResult export(@RequestBody BaseExcelConfigEntity<ReverseGenTableColumnMap> configEntity)
    {
        ReverseGenTableColumnMap queryParams = configEntity.getQueryParams();
        List<ReverseGenTableColumnMap> list = reverseGenTableColumnMapService.selectReverseGenTableColumnMapList(queryParams);
        configEntity.setTableData(list);
        return new ExcelExportUtil().export(configEntity);
    }

    /**
     * 获取反向生成字段映射详细信息
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:query')")
    @GetMapping(value = "/{mapId}")
    public AjaxResult getInfo(@PathVariable("mapId") Long mapId)
    {
        return AjaxResult.success(reverseGenTableColumnMapService.selectReverseGenTableColumnMapById(mapId));
    }

    /**
     * 新增反向生成字段映射
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:add')")
    @Log(title = "新增反向生成字段映射", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        return toAjax(reverseGenTableColumnMapService.insertReverseGenTableColumnMap(reverseGenTableColumnMap));
    }

    /**
     * 批量新增反向生成字段映射
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:add')")
    @Log(title = "批量新增反向生成字段映射", businessType = BusinessType.INSERT)
    @PostMapping(value = "/addReverseGenTableColumnMaps")
    public AjaxResult addReverseGenTableColumnMaps(@RequestBody List<ReverseGenTableColumnMap> reverseGenTableColumnMapList)
    {
        return toAjax(reverseGenTableColumnMapService.insertReverseGenTableColumnMapListBatch(reverseGenTableColumnMapList));
    }

    /**
     * 修改反向生成字段映射
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:edit')")
    @Log(title = "修改反向生成字段映射", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ReverseGenTableColumnMap reverseGenTableColumnMap)
    {
        return toAjax(reverseGenTableColumnMapService.updateReverseGenTableColumnMap(reverseGenTableColumnMap));
    }

    /**
     * 批量修改反向生成字段映射
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:edit')")
    @Log(title = "批量修改反向生成字段映射", businessType = BusinessType.UPDATE)
    @PutMapping(value = "/editReverseGenTableColumnMaps")
    public AjaxResult editReverseGenTableColumnMaps(@RequestBody List<ReverseGenTableColumnMap> reverseGenTableColumnMapList)
    {
        return toAjax(reverseGenTableColumnMapService.updateReverseGenTableColumnMapListBatch(reverseGenTableColumnMapList));
    }

    /**
     * 删除反向生成字段映射
     */
    @PreAuthorize("@ss.hasPermi('generator:ReverseGenTableColumnMap:remove')")
    @Log(title = "删除反向生成字段映射", businessType = BusinessType.DELETE)
	@DeleteMapping("/{mapIds}")
    public AjaxResult remove(@PathVariable Long[] mapIds)
    {
        return toAjax(reverseGenTableColumnMapService.deleteReverseGenTableColumnMapByIds(mapIds));
    }
}
